﻿package com.sh.game.pool
{
    import flash.utils.*;

    public class HashMap extends Object
    {
        private var _length:int;
        private var _content:Dictionary;
        private var _weakKeys:Boolean;

        public function HashMap(param1:Boolean = false)
        {
            this._weakKeys = param1;
            this._length = 0;
            this._content = new Dictionary(param1);
            return;
        }// end function

        public function get length() : int
        {
            return this._length;
        }// end function

        public function isEmpty() : Boolean
        {
            return this._length == 0;
        }// end function

        public function getKeys() : Array
        {
            var _loc_3:* = undefined;
            var _loc_1:* = new Array(this._length);
            var _loc_2:int = 0;
            for (_loc_3 in this._content)
            {
                
                _loc_1[_loc_2] = _loc_3;
                _loc_2++;
            }
            return _loc_1;
        }// end function

        public function getValues() : Array
        {
            var _loc_3:* = undefined;
            var _loc_1:* = new Array(this._length);
            var _loc_2:int = 0;
            for each (_loc_3 in this._content)
            {
                
                _loc_1[_loc_2] = _loc_3;
                _loc_2++;
            }
            return _loc_1;
        }// end function

        public function eachKey(param1:Function) : void
        {
            var _loc_2:* = undefined;
            for (_loc_2 in this._content)
            {
                
                this.param1(_loc_2);
            }
            return;
        }// end function

        public function eachValue(param1:Function) : void
        {
            var _loc_2:* = undefined;
            for each (_loc_2 in this._content)
            {
                
                this.param1(_loc_2);
            }
            return;
        }// end function

        public function each2(param1:Function) : void
        {
            var _loc_2:* = undefined;
            for (_loc_2 in this._content)
            {
                
                this.param1(_loc_2, this._content[_loc_2]);
            }
            return;
        }// end function

        public function containsValue(param1) : Boolean
        {
            var _loc_2:* = undefined;
            for each (_loc_2 in this._content)
            {
                
                if (_loc_2 === param1)
                {
                    return true;
                }
            }
            return false;
        }// end function

        public function some(param1:Function) : Boolean
        {
            var _loc_2:* = undefined;
            for (_loc_2 in this._content)
            {
                
                if (this.param1(_loc_2, this._content[_loc_2]))
                {
                    return true;
                }
            }
            return false;
        }// end function

        public function filter(param1:Function) : Array
        {
            var _loc_3:* = undefined;
            var _loc_4:* = undefined;
            var _loc_2:Array = [];
            for (_loc_3 in this._content)
            {
                
                _loc_4 = this._content[_loc_3];
                if (this.param1(_loc_3, _loc_4))
                {
                    _loc_2.push(_loc_4);
                }
            }
            return _loc_2;
        }// end function

        public function containsKey(param1) : Boolean
        {
            if (this._content[param1] === undefined)
            {
                return false;
            }
            return true;
        }// end function

        public function getValue(param1)
        {
            var _loc_2:* = this._content[param1];
            return _loc_2 === undefined ? (null) : (_loc_2);
        }// end function

        public function getKey(param1)
        {
            var _loc_2:* = undefined;
            for (_loc_2 in this._content)
            {
                
                if (this._content[_loc_2] == param1)
                {
                    return _loc_2;
                }
            }
            return null;
        }// end function

        public function add(param1, param2)
        {
            var _loc_3:* = undefined;
            if (param1 == null)
            {
                throw new ArgumentError("cannot put a value with undefined or null key!");
            }
            if (param2 === undefined)
            {
                return null;
            }
            if (this._content[param1] === undefined)
            {
                var _loc_4:String = this;
                var _loc_5:* = this._length + 1;
                _loc_4._length = _loc_5;
            }
            _loc_3 = this.getValue(param1);
            this._content[param1] = param2;
            return _loc_3;
        }// end function

        public function remove(param1)
        {
            if (this._content[param1] === undefined)
            {
                return null;
            }
            var _loc_2:* = this._content[param1];
            delete this._content[param1];
            var _loc_3:String = this;
            var _loc_4:* = this._length - 1;
            _loc_3._length = _loc_4;
            return _loc_2;
        }// end function

        public function clear() : void
        {
            this._length = 0;
            this._content = new Dictionary(this._weakKeys);
            return;
        }// end function

        public function clone() : HashMap
        {
            var _loc_2:* = undefined;
            var _loc_1:* = new HashMap(this._weakKeys);
            for (_loc_2 in this._content)
            {
                
                _loc_1.add(_loc_2, this._content[_loc_2]);
            }
            return _loc_1;
        }// end function

        public function toString() : String
        {
            var _loc_5:int = 0;
            var _loc_1:* = this.getKeys();
            var _loc_2:* = this.getValues();
            var _loc_3:* = _loc_1.length;
            var _loc_4:String = "HashMap Content:\n";
            _loc_5 = 0;
            while (_loc_5 < _loc_3)
            {
                
                _loc_4 = _loc_4 + (_loc_1[_loc_5] + " -> " + _loc_2[_loc_5] + "\n");
                _loc_5++;
            }
            return _loc_4;
        }// end function

    }
}
